<template>
  <div class="home">
    <div class="carousel">
      <el-carousel :interval="5000" arrow="always" height="500px">
        <el-carousel-item v-for="(item, index) in listData" :key="index">
          <div style="position: relative">
            <el-image
              style="width: 100%; height: 500px; position: relative"
              :src="Img_prefix + item.Adimg"
              fit="fit"
              @click="toUrl(item.Adlink)"
            >
            </el-image>

            <div class="imgtitle"><span style="margin:2rem;">{{ item.Adtitle }}</span></div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="content">
      <div class="left">
        <homePageList></homePageList>
      </div>

      <div class="right">
        <statusBar></statusBar>
      </div>
    </div>
  </div>
</template>

<script>
import statusBar from "@/components/statusBar";
import homePageList from "./homePageList/index";
import { get_advertisements } from "../../api/advertisements";
import { advertisements_img_prefix } from "../../utils/global";
export default {
  name: "Home",
  data() {
    return {
      activeName: "second",
      listData: [],
      Img_prefix: advertisements_img_prefix,
    };
  },
  components: {
    statusBar,
    homePageList,
  },
  created() {
    this.get_adcer();
  },
  methods: {
    toUrl(url) {
      window.open(url);
      // window.location.href = url;
    },
    async get_adcer() {
      let advData = await get_advertisements({
        query: {},
        sort: {
          Adnum: 1,
        },
      });
      console.log("轮播图：", advData);
      this.listData = advData.data;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  // padding: 10px 10px;
  width: 100%;
  // margin-bottom: 300px;
}
.carousel {
  width: 100%;
}
.imgtitle {
  font-size: 3rem;
  position: absolute;
  color: #ffffff;
  background-color: #3a3a3a ;
  opacity: 0.8;
  letter-spacing: 0.5rem;
  width: 100%;
  z-index: 99;
  bottom: 0rem;
  text-align: left;
}
.content {
  display: flex;
  width: 100%;
  justify-content: space-between;
  margin-top: 20px;
  .left {
    width: 74%;
  }

  .right {
    width: 25%;
  }
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 500px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
